<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<?php include(P_TEMPLATE . '/admin/header.tpl.php'); ?>
<link rel="shortcut icon" href="<?php echo W_BASE_URL;?>favicon.ico" />
<script type="text/javascript" src="<?php echo W_BASE_URL;?>js/admin/admin.js<?php echo '?v=' . SVN_VERSION; ?>"></script>
<script>
$(function(){
	admin.index.init();
});

$(function(){
	var html=['<form id="pwdfrm" name="pwdfrm" method="post">',
						'<div class="form-box">',
							'<div class="form-row">',
								'<label for="old_pwd" class="form-field">原密码</label>',
								'<div class="form-cont">',
									'<input type="password" value="" class="ipt-txt" id="old_pwd" name="old_pwd" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#opwdErr"><span id="opwdErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="form-row">',
								'<label for="text" class="form-field">新密码</label>',
								'<div class="form-cont">',
									'<input type="password" value="" class="ipt-txt" id="pwd" name="pwd" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#pwdErr"><span id="pwdErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="form-row">',
								'<label for="text" class="form-field">确认新密码</label>',
								'<div class="form-cont">',
									'<input type="password" value="" class="ipt-txt" id="re_pwd" name="re_pwd" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#rePwdErr"><span id="rePwdErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="btn-area">',
								'<a class="btn-general  highlight" id="input_ok" href="#"><span>确定</span></a>',
								'<a class="btn-general" id="input_cancle" href="#"><span>取消</span></a>',
							'</div>',
						'</div>',
					'</form>'].join('');

	window.box=Xwb.use('MgrDlg',{
		setTitle:function(title){
			this.dlg.jq('#xwb_title').html(title);
			return this;
		},

		set: function(old_pwd, pwd, re_pwd) {
			$('input[name=old_pwd]', this.dlg.jq()).val(old_pwd || '');
			$('input[name=pwd]', this.dlg.jq()).val(pwd || '');
			$('input[name=re_pwd]', this.dlg.jq()).val(re_pwd || '');
			return this;
		 },

	   show:function(){
		 this.dlg.jq('#textErr').cssDisplay(false);
		 this.dlg.display(true);
	   },

	   hide:function(){
		this.dlg.display(false);
	   },

	   onOk:function(fn){
			this.selfChk=function(data){
				fn(data.old_pwd, data.pwd, data.re_pwd);
			}
	   },

	   modeHtml:html,
	   dlgcfg:{
			cs:'win-link win-fixed',
			title:'添加管理员帐号',
			onViewReady:function(view){
				var self=this;
				$(view).find('#input_cancle').click(function(){
					self.close();
				})
			}
	   },

	   valcfg:{
		    form:'#pwdfrm',
			trigger:'#input_ok'
	   }
	});

	box.dlg.close();
});

$(function() {
	var errNodes = {
		'old_pwd': box.dlg.jq().find('#opwdErr'),
		'pwd': box.dlg.jq().find('#pwdErr'),
		're_pwd': box.dlg.jq().find('#rePwdErr')
	};
	
	var target;
	var $old_pwd =box.dlg.jq().find('#old_pwd');
	var $pwd =box.dlg.jq().find('#pwd');
	var $re_pwd =box.dlg.jq().find('#re_pwd');

	box.onOk(function(old_pwd, pwd, re_pwd) {
		var data = {
			old_pwd: old_pwd,
			pwd: pwd,
			re_pwd: re_pwd
		}
		
		$.ajax({
			url: "/admin.php?m=admin/admin.rePwd", 
			data: data,
			type: 'post',
			dataType: 'json',
			success: function(ret) {
				if (ret.rst) {
					Xwb.ui.MsgBox.tipOk('密码修改成功！');
				} else { //失败
					if (ret.errno == 400000000) { //帐号不存在
						window.location.href = '<?php echo URL('admin/admin.logout'); ?>';
					} else {
						Xwb.ui.MsgBox.alert('修改失败', ret.err);
					}
				}
				target = null;
			}
		});
	});
	
	$('#rePwd').click(function() {
		$.each(errNodes, function(i, o) {
			o.addClass('hidden');
		});
		box.setTitle('修改密码').set('', '', '').show();
	});
	function onUnreadLoad(r){
		if(r.isOk()){
			Xwb.use('adminNotice').unreadLoad(r.getData());
			setTimeout(function(){Xwb.request.adminUnread(onUnreadLoad)}, 30000);
		}
		
	}
	
	//Xwb.request.adminUnread(onUnreadLoad);

});
</script>
</head>
<?php
function chkUserPermission($chkPermissions, $superAdmin)
{
	static $userPermissions = false;
	if ($userPermissions === false)
		$userPermissions = USER::getAdmin(ADMIN_SESSION_PERMISSIONS);
	
	if (in_array(USER::aid(), $superAdmin))	return true;
	
	if (!is_array($chkPermissions))	$chkPermissions = array($chkPermissions);
	$allow = array_intersect($userPermissions, $chkPermissions);
	if (empty($allow)) return false;
	
	return true;
}
?>
<body>
		<div id="header">
			<h1>自游网广东站管理中心</h1>
			<ul>
				<?php foreach ($nav as $title => $item): ?>
					<?php if (chkUserPermission($item['nav_qx'], $superAdmin)): ?>
						<li><a href="#"><?php echo $title; ?></a></li>
					<?php endif; ?>
				<?php endforeach; ?>
			</ul>
			<p>
				<span>欢迎回来：<?php echo USER::getAdmin(ADMIN_SESSION_UNAME); ?></span>
				<span class="line">|</span>
				<a href="javascript:;" id="rePwd">修改密码</a>
				<span class="line">|</span>
				<a href="<?php echo URL('admin/admin.logout');?>">退出</a>
			</p>
		</div>

			<div id="mainDiv" class="main-frame">
				<iframe src="<?php echo URL('admin/admin.default_action');?>" id="mainframe" name="mainframe" width="100%" height="100%" frameborder="0" title="main frame content"></iframe>
			</div>
			<div id="side-menu">
				<?php foreach ($nav as $title => $item): ?>
				<?php if (chkUserPermission($item['nav_qx'], $superAdmin)): ?>
				<div class="menu-group">
					<?php foreach ($item['menus'] as $childItem): ?>
					<?php if (chkUserPermission($childItem['menu_qx'], $superAdmin)): ?>
					<h2><?php echo $childItem['menu_name']; ?></h2>
					<ul>
						<?php foreach ($childItem['menu_list'] as $row): ?>
						<?php if (chkUserPermission($row['qx'], $superAdmin)): ?>
						<li><a href="<?php echo $row['link']; ?>" target="mainframe"><?php echo $row['name']; ?></a></li>
						<?php endif; ?>
						<?php endforeach; ?>
					</ul>
					<?php endif; ?>
					<?php endforeach; ?>
				</div>
				<?php endif; ?>
				<?php endforeach; ?>
			</div>
<script type='text/javascript'>
if(!window.Xwb)Xwb={};
	Xwb.cfg={
		basePath : '<?php echo W_BASE_URL;?>'
	}
Xwb.request.basePath = Xwb.cfg.basePath;

//初始化 自适应窗口大小
var autoSize = function(){
	var height = document.documentElement.clientHeight - 89;
	$('#side-menu').css('height',height+'px');
	$('#mainDiv').css('height',height+'px');
}
autoSize();
$(window).resize(autoSize);
</script>
</body>
</html>
